home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / PowerTalk Access Modules / Sample PMSAM / PMSAM Framework / Common / CRString.h < prev    next >
Encoding:
Text File  |  1995-07-28  |  23.7 KB  |  898 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        CRString.h
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Written by:    Tim Harnett
  7.  
  8.     Copyright:    © 1992 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Notes: 
  11.     •    This file contains the definitions for the classes for manageing
  12.         OCE RStrings in the Admin program.
  13.         
  14.     •    The primary design goal is that all these classes be binary compatible
  15.         with standard OCE RStrings.  This means that taking the address of
  16.         (&crstring) will produce a OCE compatible RStringPtr.  But don't do
  17.         this! Except (maybe) because you are lazy. Rather use the defined 
  18.         coercion operators so that the compiler will automatically do this.
  19.         For example a  DirParamBlock field that is defined to be a RStringPtr
  20.         can be assigned without explicit casting.
  21.         
  22.             CRecordName userName("joe");    // there is a constructor for this
  23.             DirEnumerateGetPB pb;
  24.             pb.userName = recordName;        // cast operator defined.
  25.         
  26.         As a matter of fact it is best not use explicit casting anywhere. But rather
  27.         provide cast operators, in this example  CRString::operatorRString*() was
  28.         used.  If you see a cast be suspicious.
  29.  
  30.     •    Because these objects must be binary compatible there must be no virtual methods.
  31.         CRString::Size() and CRString::Sensitivity() virtual methods would have been great,
  32.         Tough! These class definitions are good candidates for C++'s Templates.  Because it
  33.         has no virtual methods it is safe to use the accessor methods of the base class 
  34.         when you have a CRString*. Be careful not to use Comparison or Assignment methods.
  35.         
  36.     •    The CRString class should be considered an abstract base class.  Notice that the
  37.         constructor is protected.  This means only subclasses have access to it. 
  38.         
  39.     •    Typically these objects are created on the stack.  Thier destructors do not need to
  40.         be called on failures.
  41.  
  42.     •    Even though the fields of CRString's are protected.  The cast operators will allow
  43.         violations of this hiding.
  44.         
  45.     •    CRString
  46.         CRString16        - the smallest CRString you can create.
  47.         CRString256        - the RString that can hold a pascal string, ie. Str255.
  48.         CRecordName        - the RString that can hold a OCE record name
  49.         CNetworkName
  50.         CDirectoryName
  51.         CRecordType
  52.         CAttributeType
  53.         
  54.     •    The classes are not complete.  Implementation is evolutionary. Those operators and
  55.         constructors that have been needed have been implemented.  Others will undoubtedly
  56.         be needed.
  57.     
  58.     •    About CStr255.  Because we do not want to modify MacApp to create a CStr255(CRString*)
  59.         constructor or a CStr255 operator=(CRString*) we do the following. We use CRString 
  60.         (unsigned char*) operator of the CRString in combination with the 
  61.         CRStr255::operator=(unsigned char*) to copy a CRString to a CSt255.  For example
  62.         
  63.         Foo(CStr255& str255) 
  64.         {
  65.             CRecordName userName("jane");
  66.             str255 = (unsigned char*) jane;        // copies jane to CStr255.
  67.             
  68.             // or
  69.             TRecord* user;
  70.             str255 = (unsigned char*)*user->Name();        // TRecord::Name() returns a CRString*, so we have to
  71.                                                         // dereference it once to apply the operator.
  72.         }
  73.         
  74.         Also the CSRString CStr255& operator allows us to do the following.  The compiler
  75.         picks the right cast.
  76.         
  77.         CRecordName        name("Joe");
  78.         staticText->SetText(name);
  79.         
  80.     Change History (most recent first):
  81.  
  82.          <7>     2/21/95    TMH        metrowerks changes
  83.          <6>     2/17/95    TMH        added CRecordType& CRecordType::operator =(StringPtr pstr)
  84.          <5>     1/11/95    TMH        made changes for Metroworks compiler
  85.          <4>    10/14/94    TMH        adde CDirectoryName assignment operator
  86.          <3>    10/13/94    TMH         added CRecordType assigment operator
  87.          <2>    10/11/94    TMH        added CRecordType::operator =(char* cstr)
  88.          <1>     9/20/94    TMH        Abandon RoadsideRest embrace Mercury
  89.         <17>     1/18/94    EMS        Added FormBackwardNameMethod
  90.         <16>    11/12/93    TMH        added CRString256 assignment operator
  91.         <15>     11/8/93    TMH        some assignmment operators
  92.         <14>      8/2/93    TMH        added CRString256 assignment operator
  93.         <13>     6/22/93    EMS        Added Strip
  94.         <12>     5/24/93    TMH        added assignment operator for CRString256
  95.         <11>     2/25/93    TMH        some nil checks and RStringHandle assignment operator
  96.          <10>     2/21/93    EMS        Checked in Tim's = operation overload for CRecordName and CAttrubiteType.
  97.          <9>     1/26/93    TMH        change length of CRecordName to 64
  98.          <8>     1/14/93    TMH        a14 upgrades
  99.          <7>      1/4/93    TMH        added CRString::ConvertToNumber()
  100.          <6>    12/30/92    TMH        fixe CString256 assignment operator, added CAttribute assignment
  101.                                     operator
  102.                  12/9/92    EMS        Made CRString constructor private !!!!
  103.          <4>    10/29/92    TMH        RStringHandle constructors
  104.          <3>    10/15/92    TMH        a11 upgrades
  105.          <2>     9/25/92    EMS        refined #include'ing of .h files and moved classes, globals etc.
  106.          <1>      9/8/92    TMH        The Great Project Restructuring of 1992
  107.          <4>     7/10/92    TMH        CRString* constructor for CAttributeType
  108.         <2+>     6/23/92    SMT        adding default constructor for CRString
  109.          <2>     6/23/92    TMH        fixed bugs in CRecordName constructors and assignment operator.
  110.                  5/28/92    TMH        New with A8 upgrades
  111.  
  112.     To Do:
  113. */
  114.  
  115.  
  116. #ifndef __CRString__
  117. #define __CRString__
  118.  
  119. #ifndef __PACKAGES__
  120. #include "Packages.h"
  121. #endif
  122.  
  123. #ifndef __PascalString__
  124. #include "PascalString.h"
  125. #endif
  126.  
  127.  
  128. //--    OCE    Includes
  129.  
  130. #ifndef __OCE__
  131. #include "OCE.h"
  132. #endif
  133.  
  134.  
  135.  
  136. const short kDefaultCharSet = 0;
  137. const short kCRStringBaseBodySize = 2;
  138.  
  139.  
  140.  
  141. //-----------------------------
  142. //        C R S t r i n g
  143. //-----------------------------
  144.  
  145.  
  146.  
  147.  
  148. class CRString {
  149. protected:
  150.     // Constructor
  151.     CRString();
  152.     CRString(short charSet);
  153.  
  154. public:
  155.     unsigned short fCharSet;
  156.     unsigned short fBodyLength;
  157.     unsigned char  fBody[kCRStringBaseBodySize];
  158.     
  159.         
  160. public:    
  161.     // Accessors
  162.     
  163.     unsigned short CharSet() const { return fCharSet; };
  164.     unsigned short Length() const;
  165.     unsigned short BodyLength() const;
  166.     Boolean IsEmpty() const;
  167.     Boolean IsNil() const;
  168.     void* Copy(void* destBuf) const;        // permits copying into any arbitrary buffer.
  169.     void* CopyBody(void* destBuf) const;
  170.  
  171.     // Cast Operators
  172.     
  173.     operator unsigned char*() const;
  174.     operator const void*() const;
  175.     operator const RString*() const;
  176.     operator RString*();
  177.     operator const unsigned char*();
  178.     operator const CStr255&() const;
  179.     operator CStr255&();
  180.     
  181.     long ConvertToNumber();
  182.     
  183.     void    Strip( char theChar, Boolean stripAll, Boolean stripLeading, Boolean stripTrailing );
  184.     
  185.     //  Comparisons
  186.     
  187.     friend inline Boolean operator==(const CRString& s1, const CRString& s2);
  188.     friend inline Boolean operator==(const CRString& s1, const RString* s2);
  189.  
  190.  
  191. };
  192.  
  193.  
  194. // Accessors
  195. inline unsigned short    CRString::BodyLength() const             { return fBodyLength; };
  196. inline unsigned short    CRString::Length() const                 { return fBodyLength+sizeof(ProtoRString); };
  197. inline Boolean            CRString::IsEmpty() const                 { return  fBodyLength == 0; };
  198. inline Boolean            CRString::IsNil() const                 { return this == 0;  };    // bit'o sleaze
  199. inline void*            CRString::Copy(void* destBuf) const     { BlockMove(this,destBuf,this->Length()); return destBuf; };
  200. inline void*            CRString::CopyBody(void* destBuf) const { BlockMove(fBody,destBuf,this->fBodyLength); return destBuf; };
  201.  
  202. //    Cast Operators
  203. inline CRString::operator const void*() const             { return this; };
  204. inline CRString::operator         unsigned char*() const     { return (unsigned char*) (fBody - 1); };
  205. inline CRString::operator const CStr255&() const        { return (const CStr255&) *(fBody - 1); };
  206. inline CRString::operator       CStr255&()                { return (CStr255&) *(fBody - 1); }
  207. inline CRString::operator const RString*() const        { return (const RString*) this; };
  208. inline CRString::operator         RString*()                { return (RString*) this; };
  209.  
  210.  
  211. //  Comparisons
  212. inline Boolean operator==(const CRString& s1, const CRString& s2)
  213. {    return OCERelRString(&s1, (const RString*)s2, kOCEGenericSensitive) == 0; };
  214.  
  215. inline Boolean operator==(const CRString& s1, const RString* s2)
  216. {    return OCERelRString( &s1, s2, kOCEGenericSensitive) == 0; };
  217.  
  218. inline long CRString::ConvertToNumber() {  long number = 0; StringToNum((CStr255&)*this,&number);  return number; }
  219.  
  220. //----------------------------
  221. //        C R S t r i n g 1 6 
  222. //----------------------------
  223.  
  224.  
  225. #define kRString16BodySize    16
  226.  
  227. class CRString16 : public CRString {
  228. private:
  229.     unsigned char     fData[kRString16BodySize-kCRStringBaseBodySize];
  230. public:
  231.  
  232.     // Constructors
  233.     
  234.     CRString16();
  235.     CRString16(const char* str,short charSet = kDefaultCharSet);
  236.     CRString16(const RString* rstr);
  237.     CRString16(const RStringHandle rstr);
  238.     CRString16(const CStr255& cstr255,short charSet = kDefaultCharSet);
  239.  
  240.  
  241. };
  242.  
  243. //----------------------------
  244. //        C R S t r i n g 3 2
  245. //----------------------------
  246.  
  247.  
  248. #define kRString32BodySize    32
  249.  
  250. class CRString32 : public CRString {
  251. private:
  252.     unsigned char     fData[kRString32BodySize-kCRStringBaseBodySize];
  253. public:
  254.  
  255.     // Constructors
  256.     
  257.     CRString32();
  258.     CRString32(const char* str,short charSet = kDefaultCharSet);
  259.     CRString32(const RString* rstr);
  260.     CRString32(const RStringHandle rstr);
  261.     
  262.     //    Assignment Operators
  263.     
  264.     
  265.     CRString32(const CStr255& cstr255,short charSet = kDefaultCharSet);
  266.     CRString32& operator =(const RString* rstr);
  267.     CRString32& operator =(const char* cstr);
  268.     CRString32& operator =(StringPtr cstr);
  269.  
  270. };
  271.  
  272. inline CRString32::CRString32() : CRString () {};
  273.  
  274. inline CRString32& CRString32::operator =(const char *cstr) 
  275. {
  276.     fCharSet = kDefaultCharSet;
  277.     
  278.     if( cstr != 0 ) {
  279.     
  280.         fBodyLength = strlen(cstr);
  281.         if( fBodyLength > kRString32BodySize )
  282.             fBodyLength = kRString32BodySize;
  283.         memcpy(fBody,cstr,fBodyLength);
  284.     }
  285.     return *this;
  286. };
  287.  
  288. inline CRString32& CRString32::operator =(StringPtr pstr) 
  289. {
  290.     fCharSet = kDefaultCharSet;
  291.     if( pstr != 0 ) {
  292.         fBodyLength = pstr[0];
  293.         if( fBodyLength > kRString32BodySize )
  294.             fBodyLength = kRString32BodySize;
  295.             
  296.         memcpy(fBody,&pstr[1],fBodyLength);
  297.     }
  298.     return *this;
  299. };
  300.  
  301.  
  302. inline CRString32& CRString32::operator =(const RString* rstr) 
  303. {
  304.     if( rstr != 0 ) {
  305.         fBodyLength = rstr->dataLength;
  306.         if( fBodyLength > kRString32BodySize )
  307.             fBodyLength = kRString32BodySize;
  308.         
  309.         fCharSet = rstr->charSet;
  310.         BlockMove((Ptr)rstr->body,(Ptr) fBody,fBodyLength);
  311.     }
  312.     return *this;
  313. };
  314.  
  315. //-----------------------------
  316. //    C R S t r i n g 2 5 6
  317. //-----------------------------
  318.  
  319.  
  320.  
  321. #define kRString256BodySize    kRStringMaxBytes
  322.  
  323. class CRString256 : public CRString {
  324. private:
  325.     unsigned char     fData[kRString256BodySize-kCRStringBaseBodySize];
  326. public:
  327.     // Constructor
  328.     
  329.     CRString256();
  330.     CRString256(const char* str,short charSet = kDefaultCharSet);
  331.     CRString256(const RString* rstr);
  332.     CRString256(const RStringHandle);
  333.     CRString256(const CStr255& cstr255,short charSet = kDefaultCharSet);
  334.  
  335.     // Assignment
  336.     CRString256& operator =(const RString* rstr);
  337.     CRString256& operator =(const RStringHandle rstrH);
  338.     CRString256& operator =(const CStr255& cstr);
  339.     CRString256& operator =(const CRString256& rstr);
  340.     CRString256& operator =(CRString256& rstr);
  341.     CRString256& operator =(const char* cstr);
  342.     CRString256& operator =(StringPtr cstr);
  343.  
  344. };
  345.  
  346. // Constructor
  347. inline CRString256::CRString256() : CRString() {};
  348.  
  349. // Assignment
  350. inline CRString256& CRString256::operator =(const RString* rstr) 
  351. {
  352.     if( rstr != 0 ) {
  353.         fBodyLength = rstr->dataLength;
  354.         if( fBodyLength > kRString256BodySize )
  355.             fBodyLength = kRString256BodySize;
  356.         
  357.         fCharSet = rstr->charSet;
  358.         BlockMove((Ptr)rstr->body,(Ptr) fBody,fBodyLength);
  359.     }
  360.     return *this;
  361. };
  362.  
  363. // Assignment
  364. inline CRString256& CRString256::operator =(const CRString256& rstr) 
  365. {
  366.     BlockMove(rstr,(void*)this,rstr.Length());
  367.     return *this;
  368. }
  369. inline CRString256& CRString256::operator =(CRString256& rstr) 
  370. {
  371.     BlockMove(rstr,(void*)this,rstr.Length());
  372.     return *this;
  373. }
  374.  
  375. inline CRString256& CRString256::operator =(const RStringHandle rstrH) 
  376. {
  377.     if( rstrH != 0 ) {
  378.         fBodyLength = (*rstrH)->dataLength;
  379.         if( fBodyLength > kRString256BodySize )
  380.             fBodyLength = kRString256BodySize;
  381.         
  382.         fCharSet = (*rstrH)->charSet;
  383.         BlockMove((Ptr)(*rstrH)->body,(Ptr) fBody,fBodyLength);
  384.     }
  385.     return *this;
  386. };
  387.  
  388.  
  389. inline CRString256& CRString256::operator =(const CStr255& cstr) 
  390. {
  391.     fCharSet = kDefaultCharSet;
  392.     fBodyLength = cstr.Length();
  393.     memcpy(fBody,&cstr.fStr[1],fBodyLength);
  394.     return *this;
  395. };
  396.  
  397. inline CRString256& CRString256::operator =(StringPtr pstr) 
  398. {
  399.     fCharSet = kDefaultCharSet;
  400.     if( pstr != 0 ) {
  401.         fBodyLength = pstr[0];
  402.         if( fBodyLength > kRString256BodySize )
  403.             fBodyLength = kRString256BodySize;
  404.             
  405.         memcpy(fBody,&pstr[1],fBodyLength);
  406.     }
  407.     return *this;
  408. };
  409.  
  410.  
  411. inline CRString256& CRString256::operator =(const char *cstr) 
  412. {
  413.     fCharSet = kDefaultCharSet;
  414.     
  415.     if( cstr != 0 ) {
  416.     
  417.         fBodyLength = strlen(cstr);
  418.         if( fBodyLength > kRString256BodySize )
  419.             fBodyLength = kRString256BodySize;
  420.         memcpy(fBody,cstr,fBodyLength);
  421.     }
  422.     return *this;
  423. };
  424.  
  425.  
  426. //---------------------------------------------
  427. //        C D i r e c t o r y N a m e 
  428. //--------------------------------------------
  429.  
  430.  
  431. #define kDirectoryNameBodySize    kDirectoryNameMaxBytes
  432.  
  433. class CDirectoryName : public CRString {
  434. private:
  435.     unsigned char     fData[kDirectoryNameBodySize-kCRStringBaseBodySize];
  436. public:
  437.     CDirectoryName();
  438.     CDirectoryName(const char* str,short charSet = kDefaultCharSet);
  439.     CDirectoryName(const RString* rstr);
  440.     CDirectoryName(const CRString* crstr);
  441.     CDirectoryName(const CStr255& cstr255,short charSet = kDefaultCharSet);
  442.     
  443.     CStr255& operator =(CStr255& pstr);
  444.  
  445.     //    Coercion
  446.     operator DirectoryName*();
  447.     
  448.     //  Comparisons
  449.     friend inline Boolean operator==(const CDirectoryName& s1, const CDirectoryName& s2);
  450.     friend inline Boolean operator==(const CDirectoryName& s1, const RString* s2);
  451.     
  452.     
  453.     //    assignments operators
  454.     CDirectoryName& operator =(const char *cstr); 
  455.     CDirectoryName& operator =(StringPtr pstr); 
  456.     CDirectoryName& operator =(CDirectoryName& crName);
  457.  
  458. };
  459.  
  460. // Constructors
  461. inline CDirectoryName::CDirectoryName(const CRString* crstr)
  462. {
  463.     fBodyLength = crstr->BodyLength();
  464.     
  465.     if( fBodyLength > kDirectoryNameBodySize )
  466.         fBodyLength = kDirectoryNameBodySize;
  467.     
  468.     memcpy(this,crstr,sizeof(ProtoRString)+fBodyLength);
  469.  
  470. }
  471.  
  472. inline CDirectoryName& CDirectoryName::operator =(CDirectoryName& dirName) 
  473. {
  474.     BlockMove(&dirName,(Ptr) this,dirName.Length());
  475.     return *this;
  476.  
  477. };
  478.  
  479. inline CDirectoryName& CDirectoryName::operator =(const char *cstr) 
  480. {
  481.     fCharSet = kDefaultCharSet;
  482.     fBodyLength = 0;
  483.     if( cstr != 0 ) {
  484.         fBodyLength = strlen(cstr);
  485.         
  486.         if( fBodyLength > kDirectoryNameBodySize )
  487.             fBodyLength = kDirectoryNameBodySize;
  488.             
  489.         memcpy(fBody,cstr,fBodyLength);
  490.     }
  491.     return *this;
  492. };
  493.  
  494.  
  495. inline CStr255& CDirectoryName::operator =(CStr255& pstr) 
  496. {
  497.     fCharSet = kDefaultCharSet;
  498.     fBodyLength = 0;
  499.     memcpy(pstr.fStr,(unsigned char*) this,fBodyLength+1);
  500.     return pstr;
  501. };
  502.  
  503.  
  504. inline CDirectoryName& CDirectoryName::operator =(StringPtr pstr) 
  505. {
  506.     fCharSet = kDefaultCharSet;
  507.     fBodyLength = 0;
  508.     
  509.     if( pstr != 0 ) {
  510.         fBodyLength = pstr[0];
  511.         if( pstr[0] > kDirectoryNameBodySize )
  512.             fBodyLength = kDirectoryNameBodySize;
  513.             
  514.         memcpy(fBody,&pstr[1],fBodyLength);
  515.     }
  516.     
  517.     return *this;
  518. };
  519.  
  520.  
  521.  
  522. inline CDirectoryName::CDirectoryName() { fCharSet = kDefaultCharSet; fBodyLength = 0; };
  523.  
  524. // == operators
  525.  
  526. inline Boolean operator==(const CDirectoryName& s1, const CDirectoryName& s2)
  527. {    return OCERelRString(&s1, (const RString*)s2, kOCEDirName) == 0; };
  528.  
  529. inline Boolean operator==(const CDirectoryName& s1, const RString* s2)
  530. {    return OCERelRString( &s1, s2, kOCEDirName) == 0; };
  531.  
  532. //    Coercion
  533. inline CDirectoryName::operator DirectoryName*()        { return (DirectoryName*) this; };
  534.  
  535.  
  536. //-------------------------------------
  537. //        C R e c o r d N a m e
  538. //-------------------------------------
  539.  
  540.  
  541. #define kRecordNameBodySize    64        // Note : 64 is the ADAS limit for a record name, other non-ADAS directories can have longer names.
  542. //#define kRecordNameBodySize kRStringMaxBytes
  543.  
  544. class CRecordName : public CRString {
  545.     private:
  546.         unsigned char     fData[kRecordNameBodySize-kCRStringBaseBodySize];
  547.     public:
  548.         CRecordName();
  549.         CRecordName(const char* str,short charSet = kDefaultCharSet);
  550.         CRecordName(const RString* rstr);
  551.         CRecordName(const RStringHandle rstr);
  552.         CRecordName(const CRString* crstr);
  553.         CRecordName(CRString16& crstr16);
  554.         CRecordName(const CStr255& cstr255,short charSet = kDefaultCharSet);
  555.         
  556.         // Assignment
  557.         
  558.         CStr255& operator =(CStr255& pstr);
  559.         CRecordName& operator =(const RString* rstr);
  560.         CRecordName& operator =(CRecordName& crName);
  561.         CRecordName& operator =(char* cstr);
  562.         CRecordName& operator =(StringPtr pstr);
  563.         //  Comparisons
  564.         
  565.         friend inline Boolean operator==(const CRecordName& s1, const CRecordName& s2);
  566.         friend inline Boolean operator==(const CRecordName& s1, const RString* s2);
  567.         
  568.         Boolean        FormBackwardString( CRecordName&, Boolean failMultipleBreaks = false );
  569.  
  570. };
  571.  
  572. //    Constructors
  573.  
  574.  
  575. // Assignment
  576.  
  577. inline CRecordName& CRecordName::operator =(CRecordName& crName) 
  578. {
  579.     BlockMove(&crName,(Ptr) this,crName.Length());
  580.     return *this;
  581.  
  582. };
  583.  
  584. inline CStr255& CRecordName::operator =(CStr255& pstr) 
  585. {
  586.     fCharSet = kDefaultCharSet;
  587.     memcpy((unsigned char*)fBody, (unsigned char *)&pstr.fStr[1], pstr.fStr[0]);    //can't overflow!
  588.     fBodyLength = pstr.fStr[0];
  589. //    memcpy(pstr.fStr,(unsigned char*) this,fBodyLength+1);
  590.     return pstr;
  591. };
  592.  
  593. inline CRecordName& CRecordName::operator =(char* cstr) 
  594. {
  595.     fCharSet = kDefaultCharSet;
  596.     
  597.     short slen = strlen(cstr);
  598.     if( slen > kRecordNameBodySize )
  599.         slen = kRecordNameBodySize;
  600.         
  601.     memcpy(fBody,cstr,slen);
  602.  
  603.     fBodyLength = slen;
  604.  
  605.     return *this;
  606. };
  607.  
  608.  
  609. inline CRecordName& CRecordName::operator =(StringPtr pstr) 
  610. {
  611.     fCharSet = kDefaultCharSet;
  612.     fBodyLength = 0;
  613.     
  614.     if( pstr != 0 ) {
  615.         fBodyLength = pstr[0];
  616.         if( fBodyLength > kRecordNameBodySize )
  617.             fBodyLength = kRecordNameBodySize;
  618.         
  619.         memcpy(fBody,&pstr[1],fBodyLength);
  620.     }
  621.  
  622.     return *this;
  623. };
  624.  
  625.  
  626. // == operators
  627.  
  628. inline Boolean operator==(const CRecordName& s1, const CRecordName& s2)
  629. {    return OCERelRString(&s1, (const RString*)s2, kOCERecordOrDNodeName) == 0; };
  630.  
  631. inline Boolean operator==(const CRecordName& s1, const RString* s2)
  632. {    return OCERelRString( &s1, s2, kOCERecordOrDNodeName) == 0; };
  633.  
  634.  
  635.  
  636. //-----------------------------
  637. //    C N e t w o r k N a m e
  638. //-----------------------------
  639.  
  640.  
  641.  
  642.  
  643. #define kNetworkNameBodySize    kNetworkSpecMaxBytes
  644.  
  645. class CNetworkName : public CRecordName {        // Derived from CRecordName because we it IS the name of arecord.
  646. private:
  647.     unsigned char     fData[kNetworkNameBodySize-kCRStringBaseBodySize];
  648. public:
  649.     CNetworkName();
  650.     CNetworkName(const char* str,short charSet = kDefaultCharSet);
  651.     CNetworkName(const RString* rstr);
  652.     CNetworkName(const CRString* crstr);
  653.     CNetworkName(const CStr255& cstr255,short charSet = kDefaultCharSet);
  654.  
  655.  
  656.     //    Assignment
  657.     CStr255& operator =(CStr255& pstr);
  658.  
  659.     // Coercion
  660.     operator NetworkSpec*();
  661.  
  662.  
  663.     //  Comparisons
  664.     friend inline Boolean operator==(const CNetworkName& s1, const CNetworkName& s2);
  665.     friend inline Boolean operator==(const CNetworkName& s1, const RString* s2);
  666.     
  667.  
  668. };
  669.  
  670. //    Assignment
  671. inline CStr255& CNetworkName::operator =(CStr255& pstr) 
  672. {
  673.     fCharSet = kDefaultCharSet;
  674.     memcpy(pstr.fStr,(unsigned char*) this,fBodyLength+1);
  675.     return pstr;
  676. };
  677.  
  678.  
  679. inline CNetworkName::CNetworkName() { fCharSet = kDefaultCharSet; fBodyLength = 0; };
  680.  
  681. //    Coercion
  682.  
  683. inline CNetworkName::operator NetworkSpec*()        { return (NetworkSpec*) this; };
  684.  
  685. // == operators
  686.  
  687. inline Boolean operator==(const CNetworkName& s1, const CNetworkName& s2)
  688. {    return OCERelRString(&s1, (const RString*)s2, kOCENetworkSpec) == 0; };
  689.  
  690. inline Boolean operator==(const CNetworkName& s1, const RString* s2)
  691. {    return OCERelRString( &s1, s2, kOCENetworkSpec) == 0; };
  692.  
  693.  
  694.  
  695.  
  696. //-----------------------------
  697. //    C R e c o r d T y p e
  698. //-----------------------------
  699.  
  700.  
  701.  
  702. #define kRecordTypeBodySize    kRString32Size
  703.  
  704. class CRecordType : public CRString {
  705. private:
  706.     unsigned char     fData[kRecordTypeBodySize-kCRStringBaseBodySize];
  707. public:
  708.  
  709.     // Constructors
  710.     CRecordType();
  711.     CRecordType(const char* str,short charSet = kDefaultCharSet);
  712.     CRecordType(const RString* rstr);
  713.     CRecordType(const RStringHandle rstr);
  714.     CRecordType(const CRString* crstr);
  715.     CRecordType(const CStr255& cstr255,short charSet = kDefaultCharSet);
  716.     CRecordType(short indRecTypeNum);
  717.     
  718.     //    Assignment
  719.     CStr255& operator =(CStr255& pstr);
  720.     CRecordType& operator =(const RString* rstr);
  721.     CRecordType& operator =(CRecordType& crName);
  722.     CRecordType& operator =(char* cstr);
  723.     CRecordType& operator =(StringPtr pstr);
  724.     
  725.     //  Comparisons
  726.     friend inline Boolean operator==(const CRecordType& s1, const CRecordType& s2);
  727.     friend inline Boolean operator==(const CRecordType& s1, const RString* s2);
  728.     friend inline Boolean operator!=(const CRecordType& s1, const CRecordType& s2);
  729.     friend inline Boolean operator!=(const CRecordType& s1, const RString* s2);
  730.     
  731. };
  732.  
  733.  
  734. //    Constructors
  735. inline CRecordType::CRecordType() { fCharSet = kDefaultCharSet; fBodyLength = 0; };
  736.  
  737.  
  738. // Assignment
  739.  
  740. inline CRecordType& CRecordType::operator =(CRecordType& crType) 
  741. {
  742.     BlockMove(&crType,(Ptr) this,crType.Length());
  743.     return *this;
  744.  
  745. };
  746.  
  747.  
  748. inline CStr255& CRecordType::operator =(CStr255& pstr) 
  749. {
  750.     fCharSet = kDefaultCharSet;
  751.     memcpy(pstr.fStr,(unsigned char*) this,fBodyLength+1);
  752.     return pstr;
  753. };
  754.  
  755.  
  756. inline CRecordType& CRecordType::operator =(char* cstr) 
  757. {
  758.     fCharSet = kDefaultCharSet;
  759.     
  760.     short slen = strlen(cstr);
  761.     if( slen > kRecordTypeBodySize )
  762.         slen = kRecordTypeBodySize;
  763.         
  764.     memcpy(fBody,cstr,slen);
  765.  
  766.     fBodyLength = slen;
  767.  
  768.     return *this;
  769. }
  770. inline CRecordType& CRecordType::operator =(StringPtr pstr) 
  771. {
  772.     fCharSet = kDefaultCharSet;
  773.     fBodyLength = 0;
  774.     
  775.     if( pstr != 0 ) {
  776.         fBodyLength = pstr[0];
  777.         if( fBodyLength > kRecordTypeBodySize )
  778.             fBodyLength = kRecordTypeBodySize;
  779.         
  780.         memcpy(fBody,&pstr[1],fBodyLength);
  781.     }
  782.  
  783.     return *this;
  784. };
  785.  
  786.  
  787.  
  788. //    Constructors
  789. inline CRecordType::CRecordType(short indRecTypeNum) { *this = OCEGetIndRecordType(indRecTypeNum); };
  790.  
  791.  
  792.  
  793. // Comparisons
  794. inline Boolean operator==(const CRecordType& s1, const CRecordType& s2)
  795. {    return OCERelRString(&s1, (const RString*)s2, kOCERecordType) == 0; };
  796.  
  797. inline Boolean operator==(const CRecordType& s1, const RString* s2)
  798. {    return OCERelRString( &s1, s2, kOCERecordType) == 0; };
  799.  
  800.  
  801. inline Boolean operator!=(const CRecordType& s1, const CRecordType& s2)
  802. {    return OCERelRString(&s1, (const RString*)s2, kOCERecordType) != 0; };
  803.  
  804. inline Boolean operator!=(const CRecordType& s1, const RString* s2)
  805. {    return OCERelRString( &s1, s2, kOCERecordType) != 0; };
  806.  
  807.  
  808.  
  809. //-----------------------------
  810. //    C A t t r i b u t e T y p e
  811. //-----------------------------
  812.  
  813.  
  814.  
  815. #define kAttributeTypeBodySize    kAttributeTypeMaxBytes
  816.  
  817. class CAttributeType : public CRString {
  818. private:
  819.     unsigned char     fData[kAttributeTypeBodySize-kCRStringBaseBodySize];
  820. public:
  821.     CAttributeType();
  822.     CAttributeType(const char* str,short charSet = kDefaultCharSet);
  823.     CAttributeType(const RString* rstr);
  824.     CAttributeType(const RStringHandle rstr);
  825.     CAttributeType(const CRString* crstr);
  826.     CAttributeType(const CStr255& cstr255,short charSet = kDefaultCharSet);
  827.     
  828.     CStr255& operator =(CStr255& pstr);
  829.     CAttributeType& operator =(char* cstr);
  830.     CAttributeType& operator =(const RString* rstr);
  831.     CAttributeType& operator =(CAttributeType& crName);
  832.     
  833.     //  Coercion
  834.     operator AttributeType*();
  835.     
  836.     
  837.     //  Comparisons
  838.     friend inline Boolean operator==(const CAttributeType& s1, const CAttributeType& s2);
  839.     friend inline Boolean operator==(const CAttributeType& s1, const RString* s2);
  840.     
  841. };
  842.  
  843.  
  844. inline CAttributeType& CAttributeType::operator =(CAttributeType& attrType) 
  845. {
  846.     BlockMove(&attrType,(Ptr) this,attrType.Length());
  847.     return *this;
  848.  
  849. };
  850.  
  851.  
  852. inline CStr255& CAttributeType::operator =(CStr255& pstr) 
  853. {
  854.     fCharSet = kDefaultCharSet;
  855.     memcpy(pstr.fStr,(unsigned char*) this,fBodyLength+1);
  856.     return pstr;
  857. };
  858.  
  859. // Assignment
  860. inline CAttributeType& CAttributeType::operator =(const RString* rstr) 
  861. {
  862.     memcpy(this,rstr,rstr->dataLength+sizeof(ProtoRString));
  863.     return *this;
  864. };
  865.  
  866. inline CAttributeType& CAttributeType::operator =(char* cstr) 
  867. {
  868.     fCharSet = kDefaultCharSet;
  869.     
  870.     short slen = strlen(cstr);
  871.     if( slen > kAttributeTypeBodySize )
  872.         slen = kAttributeTypeBodySize;
  873.         
  874.     memcpy(fBody,cstr,slen);
  875.  
  876.     fBodyLength = slen;
  877.  
  878.     return *this;
  879. };
  880.  
  881. inline CAttributeType::CAttributeType() { fCharSet = kDefaultCharSet; fBodyLength = 0; };
  882.  
  883. // Coercion
  884.  
  885. inline CAttributeType::operator AttributeType*()        { return (AttributeType*) this; };
  886.  
  887. // == operators
  888.  
  889. inline Boolean operator==(const CAttributeType& s1, const CAttributeType& s2)
  890. {    return OCERelRString(&s1, (const RString*)s2, kOCEAttrType) == 0; };
  891.  
  892. inline Boolean operator==(const CAttributeType& s1, const RString* s2)
  893. {    return OCERelRString( &s1, s2, kOCEAttrType) == 0; };
  894.  
  895.  
  896.  
  897. #endif __CRSTRING__
  898.